<!--
 * @Author: ZhaoZhiqi
 * @Date: 2022-11-01 17:04:59
 * @LastEditors: ZhaoZhiqi
 * @LastEditTime: 2022-11-01 18:34:07
 * @Description: 惠企政策列表
 * @FilePath: \tuanfeng-mini\src\pages\policy.vue
-->
<template>
    <div class="container">
        <template v-if="!loading && list.length">
            <div class="item" v-for="item in list" @click="toDetail(item)">
                <div class="title">{{item.title}}</div>
                <div class="time">{{item.publishTimeStr}}</div>
            </div>
        </template>
        <Empty v-if="!loading && !list.length"></Empty>
    </div>
</template>
<script>
import Empty from "../components/Empty.vue";
import { getPolicyListAPI } from "../api/article";
export default {
    components: { Empty },
    data() {
        return {
            loading: false,
            list: [],
            title: "",
        };
    },
    onShareAppMessage() {},
    onLoad(options) {
        let { id, title } = options;
        this.title = title;

        wx.setNavigationBarTitle({ title });

        this.loading = true;
        wx.showLoading({
            title: "加载中...",
        });
        getPolicyListAPI({ typeId: id }).then((res) => {
            this.list = res.data;
            wx.hideLoading();
            this.loading = false;
        });
    },
    methods: {
        openDocument(url) {
            wx.showLoading({
                title: "打开文件中...",
            });
            wx.downloadFile({
                url,
                success: function (res) {
                    const filePath = res.tempFilePath;
                    wx.openDocument({
                        filePath: filePath,
                        success: function (res) {
                            wx.hideLoading();
                            console.log("打开文档成功");
                        },
                    });
                },
            });
        },
        toPage(url, params) {
            this.$u.route({ url, params });
        },
        toDetail(item) {
            if (item.discountPolicyType === 3) {
                this.toPage("pages/policy_detail", {
                    id: item.id,
                    title: item.title,
                    from: "favorable_policy",
                });
            } else {
                this.openDocument(item.accessory);
            }
        },
    },
};
</script>
<style scoped lang="scss">
@import "../assets/scss/common.scss";

.container {
    min-height: 100vh;
    background-color: #fff;
    box-sizing: border-box;
    padding: 5px 15px;
    .item {
        border-bottom: 1px solid #efefef;
        padding: 10px 5px;
        &:last-child {
            border: none;
        }
        .title {
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            overflow: hidden;
            margin-bottom: 5px;
            color: #0c92ff;
        }
        .time {
            color: $color_secondary-text;
        }
    }
}
</style>
